home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / CTXFLOPN.SPP < prev    next >
Text File  |  1997-05-06  |  2KB  |  91 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // CTXFLOPN.SPP
  6. //    Provides the implementation for context sensitive File Dialogs.  This 
  7. //    provides for maintaince of a current directory for each context that the 
  8. //    FileOpen dialog is used in while preserving Windows' idea of the current 
  9. //    directory.
  10. //
  11. // $Revision:   1.1  $
  12. //
  13. //----------------------------------------------------------------------------
  14.  
  15. import "cw3220mt.dll" {
  16.    int fnsplit(const char *fullname, char *drive, char *dir, char *name, char *ext);
  17. };
  18.  
  19. import IDE;
  20.  
  21. ContextSensitiveFileDialog(theRequestorsName, prompt, initialSpec){
  22.    PushCurrentDirectory();
  23.  
  24.    RestoreDirectory(theRequestorsName);
  25.    
  26.    declare theFileName = IDE.FileDialog(prompt, initialSpec);
  27.    if(theFileName != ""){
  28.       RememberDirectory(theRequestorsName, ExtractDirectoryName(theFileName));
  29.    }  
  30.    
  31.    PopCurrentDirectory();
  32.  
  33.    return theFileName;
  34. }
  35.  
  36. ExtractDirectoryName(fullname){
  37.    declare drive;
  38.    declare dir;
  39.    declare name;
  40.    declare ext;
  41.  
  42.    declare type = fnsplit(fullname, drive, dir, name, ext);
  43.  
  44.    return (drive + dir);
  45. }
  46.  
  47. declare array rememberer[]; 
  48.  
  49. RememberDirectory(forWho, dirToStore){
  50.    rememberer[forWho] = dirToStore;
  51. }
  52.  
  53. RestoreDirectory(forWho){
  54.    if(initialized(rememberer)){
  55.       if(initialized(rememberer[forWho])){
  56.          declare theStoredDir = rememberer[forWho];
  57.          if(theStoredDir != ""){
  58.             SetCurrentDirectory(theStoredDir);
  59.          }
  60.       }
  61.    }
  62. }
  63.  
  64. class DirectoryStack{
  65.    declare top = NULL;
  66.    Push(item){
  67.       item.next = top;
  68.       top = item;
  69.    }      
  70.    Pop(){
  71.       declare rv = top;
  72.       top = top.next;
  73.       return rv;
  74.    }
  75. };
  76.  
  77. class DirectoryRecord (dName){
  78.    declare dirName = dName;
  79.    declare next;
  80. };
  81.  
  82. declare dirStack = new DirectoryStack;
  83.  
  84. PushCurrentDirectory(){
  85.    dirStack.Push(new DirectoryRecord(GetCurrentDirectory()));
  86. }
  87.  
  88. PopCurrentDirectory(){
  89.    SetCurrentDirectory(dirStack.Pop().dirName);
  90. }
  91.